public class Leetcode1832 {

    public static void main(String[] args) {
        System.out.println(checkIfPangram1("thequickbrownfoxjumpsoverthelazydog"));
        System.out.println(checkIfPangram1("leetcode"));
    }

    /**
     * 朴素做法
     *
     * @param sentence
     * @return
     */
    public static boolean checkIfPangram(String sentence) {
        if (sentence.length() < 26) {
            return false;
        }

        boolean[] has = new boolean[26];
        int res = 0;
        for (char c : sentence.toCharArray()) {
            if (!has[c - 'a']) {
                has[c - 'a'] = true;
                res++;
            }

            if (res == 26) {
                return true;
            }
        }

        return false;
    }

    private static final int SUCCESS = (1 << 26) - 1;

    public static boolean checkIfPangram1(String sentence) {
        int count = 0;
        for (char c : sentence.toCharArray()) {
            count |= 1 << (c - 'a');

            if (count == SUCCESS) {
                return true;
            }
        }

        return false;
    }

    public static boolean checkIfPangram2(String sentence) {
        return sentence.chars().distinct().count() == 26;
    }
}
